/**
 * Created by shixc on 2019/4/2
 */
define(function () {

    var self,
        app = win.app,
        catalogs = [],
        searchData = {
            keyword: '',
            GWAK006: ''
        },
        pageUi;

    var Gwaq556 = app.Module.extend({

        init: function () {
            self = this;
            self._super({}, win);
            self.getCatalogs();
        },
        getCatalogs: function () {
            searchData.GWAK006 = '1';
            catalogs.push({GWAK006: 1, GWAK: '有商机', count: 0}, {GWAK006: 2, GWAK: '无商机', count: 0});
            app.ajax({
                xurl: "api/wx/gwaq554/getGwaq556Count",
                xdata: {},
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data;
                        catalogs[0].count = data.count1;
                        catalogs[1].count = data.count2;
                    }
                }
            });
            catalogs.forEach(function (v, i) {
                var pDivId = 'content' + catalogs[i].GWAK006 + i;
                self._refreshIds.push(pDivId);
                pageUi.right_tab.append('<div id="' + pDivId
                    + '" class="mui-control-content mui-scroll-wrapper' + (i == 0 ? " mui-active" : '') + '"><div class="mui-scroll"><classesitem-template :model="items"></classesitem-template></div></div>');
            });

            self._initRefreshById(win, 'content' + searchData.GWAK006 + '0');

        },
        _initRefresh: function () { // 实例化刷新组件
            this._super(win);
        },
        _refreshCb: function (obj) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: "api/wx/gwaq554/getGwaq556List",
                xdata: {
                    page:obj.page+1,
                    limit: obj.limit,
                    GWAK006: searchData.GWAK006,
                    keyword: searchData.keyword
                },
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data;
                        _super({
                            obj: obj,
                            data: data.data,
                            nodata: '暂无拜访信息...'
                        });
                    }
                }
            });
        },
        _lazy: function () {
            this._super();
            mui('#scrollleft').scroll({
                deceleration: 0.0005
            });
        },

        _ready: function () {
            Vue.component('classesitem-template', {
                template: app.getByid(doc, 'classesitem-template'),
                props: {
                    model: Array
                },
                data: function () {
                   return {
                       GWAK006:searchData.GWAK006
                   }
                },
                methods: {}
            });

            new Vue({
                el: app.getByid(doc, 'segmentedControls'),
                data: {
                    catalogs: catalogs
                },
                methods: {
                    showCatalogGoods: function (i, GWAH001) {
                        searchData.GWAK006 = GWAH001;
                        self._initRefreshById(win, 'content' + searchData.GWAK006 + '' + i);
                    }
                }
            });
            new Vue({
                el: app.getByid(doc, 'searchDiv1'),
                data: searchData,
                methods: {
                    serchData: function () {
                        self._refresh();
                    }
                }
            });

            pageUi = {
                right_tab: $('#tab-content')
            };

        }
    });

    return new Gwaq556();

});